/**
 * @file codeforces/1696/a/main.cpp
 * @brief
 * @see
 * @author Ruiming Guo (guoruiming@stu.scu.edu.cn)
 * @copyright 2022
 * @date 2022/6/26 20:27:34
 **/

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
const int N = 2010;
int a[N];
int main() {
  // High rating and good luck!
  int tc;
  cin >> tc;
  while (tc--) {
    int n, z;
    cin >> n >> z;
    for (int i = 1; i <= n; ++i) {
      cin >> a[i];
      a[i] |= z;
    }
    cout << *max_element(a + 1, a + n + 1) << endl;
  }
  return 0;
}
